package com.atguigu.controller;


import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.entity.PlatformPropertyValue;
import com.atguigu.result.RetVal;
import com.atguigu.service.PlatformPropertyKeyService;
import com.atguigu.service.PlatformPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性表 前端控制器
 * </p>
 *
 * @author GuoJH
 * @since 2021-08-21
 */
//@CrossOrigin
@RestController
@RequestMapping("/product")
public class PlatformPropertyController {
    @Autowired
    private PlatformPropertyKeyService propertyKeyService;
    @Autowired
    private PlatformPropertyValueService propertyValueService;

    //根据分类的id获取平台属性对应的key值
    @GetMapping("/getPlatformPropertyByCategoryId/{category1Id}/{category2Id}/{category3Id}")
    public RetVal getPlatformPropertyByCategoryId(@PathVariable Long category1Id,
                                                  @PathVariable Long category2Id,
                                                  @PathVariable Long category3Id){
        List<PlatformPropertyKey> propertyKeyList =
                propertyKeyService.getPlatformPropertyByCategoryId(category1Id,category2Id,category3Id);
        return RetVal.ok(propertyKeyList);
    }
    //根据平台属性key获取平台属性值
    @GetMapping("/getPropertyValueByPropertyKeyId/{propertyKeyId}")
    public RetVal getPropertyValueByPropertyKeyId(@PathVariable Long propertyKeyId){
        List<PlatformPropertyValue> propertyValueList =
                propertyValueService.getPropertyValueByPropertyKeyId(propertyKeyId);
        return RetVal.ok(propertyValueList);
    }
    //添加平台属性key
    @PostMapping("/savePlatformProperty")
    public RetVal savePlatformProperty(@RequestBody PlatformPropertyKey platformPropertyKey){
        propertyKeyService.savePlatformProperty(platformPropertyKey);
        return RetVal.ok();
    }

    //根据skuId获取平台属性
    @GetMapping("/getPlatformPropertyBySkuId/{skuId}")
    public List<PlatformPropertyKey> getPlatformPropertyBySkuId(@PathVariable Long skuId){
        List<PlatformPropertyKey> list = propertyKeyService.getPlatformPropertyBySkuId(skuId);
        return list;
    }
}

